package com.liuke.study.thread;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * TODO
 *
 * @author wangjwy
 * @date 2019/11/4 13:47
 * @since 1.0.0
 */
public class Test10 {

	public static void main(String[] args) throws InterruptedException {

		runTest();
		// executorService.shutdown();
	}

	private static void runTest() throws InterruptedException {
		ExecutorService executorService = new ThreadPoolExecutor(10,10,4, TimeUnit.SECONDS, new LinkedBlockingQueue<>());
		final CountDownLatch countDownLatch = new CountDownLatch(2);
		List<Future<Boolean>> list = new ArrayList<>();
		Future<Boolean> future = executorService.submit(new Callable<Boolean>(){
			@Override
			public Boolean call() throws Exception {
				Thread.sleep(1000);
				countDownLatch.countDown();
				return new Boolean(true);
			}
		});
		list.add(future);
		Future<Boolean> future2 = executorService.submit(new Callable<Boolean>(){
			@Override
			public Boolean call() throws Exception {
				Thread.sleep(2000);
				countDownLatch.countDown();
				return new Boolean(false);
			}
		});
		list.add(future2);

		countDownLatch.await();
		System.out.println("wait 完成");

		for (Future<Boolean> futureResult : list) {
			try {
				System.out.println(futureResult.get());
			} catch (InterruptedException e) {
				e.printStackTrace();
			} catch (ExecutionException e) {
				e.printStackTrace();
			}
		}

		System.out.println("over");
	}

}
